package com.tulele.vtool.service.impl;

import com.tulele.vtool.mapper.UserImpressionInfoMapper;
import com.tulele.vtool.model.UserImpressionInfo;
import com.tulele.vtool.model.combinedEntity.CombinedUserCurImpressionInfo;
import com.tulele.vtool.service.IUserImpressionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserImpressionInfoServiceImpl implements IUserImpressionInfoService {

    @Autowired
    private UserImpressionInfoMapper userImpressionInfoMapper;

    @Override
    public List<CombinedUserCurImpressionInfo> getUserCurImpression(Integer userId) {
        return userImpressionInfoMapper.queryUserCurImpression(userId);
    }

    @Override
    public int addUserImpression(Integer userId, String impressionName) {

        //查询当前印象状态
        UserImpressionInfo queryImpressionInfo = new UserImpressionInfo();
        queryImpressionInfo.setUserId(userId);
        queryImpressionInfo.setImpressionName(impressionName);
        UserImpressionInfo impressionInfoInDB = userImpressionInfoMapper.queryUserImpressionStatus(queryImpressionInfo);

        if (impressionInfoInDB == null) {
            UserImpressionInfo addImpressionInfo = new UserImpressionInfo();
            addImpressionInfo.setUserId(userId);
            addImpressionInfo.setImpressionName(impressionName);
            addImpressionInfo.setImpressionCount(0);
            addImpressionInfo.setImpressionStatus(1);
            addImpressionInfo.setCreateTime(new Date());
            userImpressionInfoMapper.addUserImpressionInfo(addImpressionInfo);
        } else {

            UserImpressionInfo updateImpressionInfo = new UserImpressionInfo();
            updateImpressionInfo.setId(impressionInfoInDB.getId());
            updateImpressionInfo.setImpressionCount(0);
            updateImpressionInfo.setImpressionStatus(1);
            updateImpressionInfo.setModifyTime(new Date());
            userImpressionInfoMapper.updateUserImpressionInfo(updateImpressionInfo);
        }

        return 0;
    }

    @Override
    public int newUserImpression (Integer userId, String impressionName) {

        UserImpressionInfo addImpressionInfo = new UserImpressionInfo();
        addImpressionInfo.setUserId(userId);
        addImpressionInfo.setImpressionName(impressionName);
        addImpressionInfo.setImpressionCount(0);
        addImpressionInfo.setImpressionStatus(1);
        addImpressionInfo.setCreateTime(new Date());
        userImpressionInfoMapper.addUserImpressionInfo(addImpressionInfo);

        return 0;
    }

    @Override
    public int agreeUserImpression(Integer impressionId) {
        UserImpressionInfo userImpressionInfo = new UserImpressionInfo();
        userImpressionInfo.setId(impressionId);
        userImpressionInfo.setModifyTime(new Date());
        return userImpressionInfoMapper.agreeUserImpression(userImpressionInfo);
    }

    @Override
    public int modifyUserImpressionInfo(UserImpressionInfo userImpressionInfo) {
        return userImpressionInfoMapper.updateUserImpressionInfo(userImpressionInfo);
    }

    @Override
    public Integer getUserImpressionAgreeCount(Integer impressionId) {
        return userImpressionInfoMapper.queryUserImpressionAgreeCount(impressionId);
    }

}
